<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>APP型号判断</title>
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
</head>

<body>
    <div id="nav"></div>
    <hr>
    <div id="parse" style="color: red;"></div>

</body>

</html>

<script>

    "use strict"

    //ua中是否包含某个字符串
    function uaContain(str) {
        var ua = navigator.userAgent;

        
        // var ua = 'Mozilla/5.0 (Linux; U; Android 10; zh-cn; M2006J10C Build/QP1A.190711.020) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/79.0.3945.147 Mobile Safari/537.36 XiaoMi/MiuiBrowser/14.2.22';

        return ua.toLowerCase().indexOf(str) !== -1
    }

    //是否在微信内
    function isWeixin() {
        return uaContain('micromessenger');
    }

    //是否安卓
    function isAndroid() {
        return uaContain('android') || uaContain('adr');
    }

    //是否ios
    function isIOS() {
        return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);;
    }


    nav.innerHTML = navigator.userAgent;



    function init() {

        if (isWeixin()) {
            alert('当前在微信内，请用手机浏览器打开')
            return
        }

        if (isAndroid()) {
            processAndroid();

        } else if (isIOS()) {
            processIOS()

        } else {
            alert('当前系统既不是安卓，也不是IOS')
            return
        }

    }

    function processAndroid() {
        alert('安卓手机')


        var keyWords = {
            "华为": ['huawei', 'honor'],
            "小米": ['mi ', 'xiaomi', 'redmi', 'mix '],
            "OPPO": ['oppo', 'pacm00', 'pccm00'],
            "VIVO": ['vivo'],
        }

        function check(brand){
            var arr = keyWords[brand];
            for(var i=0; i<arr.length; i++){
                if(uaContain(arr[i])){
                    return true;
                }
            }

            return false;
        }

        var isHuawei = check('华为');
        var isXiaomi = check('小米');
        var isOppo = check('OPPO');
        var isVivo = check('VIVO');

        if(isHuawei){
            alert('华为手机')
        }else if(isXiaomi){
            alert('小米手机')
        }else if(isOppo){
            alert('Oppo手机')
        }else if(isVivo){
            alert('Vivo手机')
        }else{
            alert('其他安卓手机')
        }

    }

    function processIOS() {
        alert('苹果手机')

    }



    init()

</script>